using AutoMapper;
using CoreProject.Model;
using CoreProject.DTO;
using MVCManage.Api;

namespace CoreProject.Api
{
  public class AutoMapperConfigs : Profile
  {
    //添加你的实体映射关系.
    public AutoMapperConfigs()
    {
            //Entity 转 Dto

            //          CreateMap<Good, GoodDto>()
            ////属性不一致匹配
            //              .ForMember(dest => dest.TypeName, opt => opt.MapFrom(src => src.TidNavigation.Name))
            //              //映射发生之前
            //              .BeforeMap((source, dto) =>
            //              {
            //                  //可以较为精确的控制输出数据格式
            //                  //dto.CreateTime = Convert.ToDateTime(source.CreateTime).ToString("yyyy-MM-dd");
            //                  dto.TypeName = source.TidNavigation.Name;
            //              })
            //              //映射发生之后
            //              .AfterMap((source, dto) =>
            //              {
            //                  //code ...
            //              })
            //              .ReverseMap();

            //UserDto转UserEntity.
            //CreateMap();
            //订单管理转dto
      
            CreateMap<HjqStoreInfo, HJQ_store_infoDto>().ForMember(dest => dest.shopDate, opt => opt.MapFrom(src => src.ShopDate.ToDateTime(TimeOnly.MinValue)));
            //创建一条转换规则
            CreateMap<User, UserDto>()
     .ForMember(dest => dest.Birthday, opt => opt.MapFrom(src => src.Birthday.ToDateTime(TimeOnly.MinValue)))
     .ForMember(dest => dest.RoleName, opt => opt.MapFrom(src => src.Role.RoleName))
     .ForMember(dest => dest.DeptName, opt => opt.MapFrom(src => src.Role.Dept.DeptName))
     .ForMember(dest => dest.Path, opt => opt.MapFrom(src => src.Img.Path));

      CreateMap<UserWriteDto, User>()
      .ForMember(dest => dest.Birthday, opt => opt.MapFrom(src => DateOnly.Parse(src.Birthday.ToString("yyyy-MM-dd"))));

            CreateMap<GoodWriteDto, Good>();

      CreateMap<Role, RoleDto>()
      .ForMember(dest => dest.DeptName, opt => opt.MapFrom(src => src.Dept.DeptName));
            CreateMap<AddRoleDto, Role>();
      CreateMap<Image, ImageDto>();

            CreateMap<Menu, MenuDto>();
            CreateMap<MenuDto, Menu>();
            //CreateMap<User, UserDto>().ReverseMap();
            CreateMap<Authority, AuthHsDto>().ForMember(n => n.MenuName, m => m.MapFrom(p => p.Menu.MenuName))
                .ForMember(n => n.ParentId, m => m.MapFrom(p => p.Menu.ParentId));
            CreateMap<Department, DepartmentsDto>();
            CreateMap<DepartmentsDto,Department>();
            CreateMap<Message, MessageDto>();
            CreateMap<MessageDto, Message>();
            CreateMap<GoodsType, GoodTypeDto>();

        }
  }
}
